<template>
  <div>
      <table>
          <tr>
              <td>id</td>
              <td>用户名</td>
              <td>会员等级</td>
              <td>操作</td>
          </tr>
          <tr v-for="i in huilist" :key="i.id">
              <td>{{i.id}}</td>
              <td>{{i.username}}</td>
              <td>{{i.level | change_level}}</td>
              <td><button @click="sheng(i.id)">升级</button></td>
          </tr>
      </table>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
           huilist:[], 
        }
    },methods: {
        hui(){
            axios({
                url:"http://127.0.0.1:8000/huilist",
                method:"post"
            }).then(resp=>{
                this.huilist = resp.data
            })
        },
        sheng(uid){
            axios({
                url:"http://127.0.0.1:8000/huilist",
                method:"put",
                data:{
                    "uid":uid
                }
            }).then(resp=>{
                this.$router.go(0)
                alert(resp.data.msg)
            })
        },
    },created() {
        this.hui()
    },filters:{
        change_level(value){
            if(value==1){
                return "普通用户"
            }else if(value==2){
                return "vip用户"
            }
        }
    }
}
</script>

<style>

</style>